﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：FeedBack.aspx.cs
    // 文件功能描述：消息管理：新增反馈
    // 创建标识：吕海乐2009-5-20
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.Web.Hospitals.MessageMange
{
    public partial class FeedBackAdd : BasePage
    {
        IBLL_Message im = Factory.BLL_Message();
        public FeedBackAdd()
        {
            this.ModuleNo = "";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            tdSender.InnerText = CurrentAccount.GetUser().Org.OrgName;
            hfdSender.Value = CurrentAccount.GetUser().Org.OrgID;
            txtRecivedPerson.Attributes.Add("readonly", "readonly");
        }

        /// <summary>
        /// 发送消息
        /// </summary>
        private void SendMessage()
        {
            string reciverIds = hfdRecivedPerson.Value.TrimEnd(',');
            string reciverNames = txtRecivedPerson.Text.TrimEnd(',');

            if (string.IsNullOrEmpty(reciverIds) || string.IsNullOrEmpty(reciverNames))
            {
                HZ.Web.WebUtil.Alert("请选择收件人！", this);
                txtRecivedPerson.Focus();
                return;
            }
            if(string.IsNullOrEmpty(txtTitle.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("标题不能为空！", this);
                txtTitle.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtContent.Value))
            {
                HZ.Web.WebUtil.Alert("反馈内容不能为空！",this);
                txtContent.Focus();
                return;
            }

            string[] arrayIds = reciverIds.Split(',');
            string[] arraryNames = reciverNames.Split(',');

            //剔除重复的
            List<string> list = new List<string>();

            foreach (var item in arrayIds)
            {
                if (!list.Contains(item))
                {
                    list.Add(item);
                }
            }

            IList<FeedBack> feedBackList = new List<FeedBack>();

            //发送反馈
            foreach (var item in list)
            {
                FeedBack aFeedBack = new FeedBack();
                aFeedBack.Content = txtContent.Value;
                aFeedBack.FeedBackID = Guid.NewGuid().ToString();
                aFeedBack.Title = txtTitle.Text;
                aFeedBack.Reciever = item;
                aFeedBack.Sender = hfdSender.Value;
                aFeedBack.SendTime = DateTime.Now;
                aFeedBack.Status = 0;
                feedBackList.Add(aFeedBack);
            }

            int flag = im.AddFeedBack_Batch(feedBackList);

            if (flag == 1)
            {
                PageInfo("反馈发送成功！", this.ReturnUrl);
            }
            else
            {
                PageError("反馈发送失败！", this.ReturnUrl);
            }


        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            SendMessage();
        }

    }
}
